<!DOCTYPE html>
<html lang="zh">

<head>
    <meta charset="utf-8" />
    <title>诊断结果管理</title>
    <meta name="renderer" content="webkit">
    <link rel="shortcut icon" href="../img/favicon.ico">
    <link rel="Bookmark" href="../img/favicon.ico"/>
    <script src="../js/boot.js" type="text/javascript"></script>
</head>

<body>
    <div class="bigdiv">
        <!--<div class="test" style="width: 300px;height: 300px;background: rgba(0,0,0,.1)">-->
            <!--<div class="test1">-->
                <!---->
            <!--</div>-->
            <!--<div class="test1">-->
                <!---->
            <!--</div>-->
            <!--<div class="test1">-->
                <!---->
            <!--</div>-->
            <!--<div class="test1">-->
                <!---->
            <!--</div>-->
        <!--</div>-->
        <div class="bottontitle">
            <span>基本信息</span>
        </div>
        <div class="ZiliaoK">
            <div>
                <div class="userimg"></div>
                <div class="usertext">
                </div>
            </div>
        </div>
        <div style="clear: left;"></div>
        <div>
            <ol class="card-list">
                <li class="card-disabled">
                    <div class="card-item">
                        <fieldset>
                            <legend>
                                <label>羊穿<input type="checkbox" data-inspectionItemId="1" class="inspection-item-check" id="inspection-item-1-check" value="on"></label>
                            </legend>
                            <ul id="inspection-item-1-list">
                            </ul>
                        </fieldset>
                        <div class="card-shade">
                            <span class="card-btn"><i class="fa fa-pencil"></i>登记结果</span>
                        </div>
                    </div>
                </li>
                <li class="card-disabled">
                    <div class="card-item">
                        <fieldset>
                            <legend>
                                <label>脐穿<input type="checkbox" data-inspectionItemId="2" class="inspection-item-check" id="inspection-item-2-check" value="on"></label>
                            </legend>
                            <ul id="inspection-item-2-list">
                            </ul>
                        </fieldset>
                        <div class="card-shade">
                            <span class="card-btn"><i class="fa fa-pencil"></i>登记结果</span>
                        </div>
                    </div>
                </li>
                <li class="card-disabled">
                    <div class="card-item">
                        <fieldset>
                            <legend>
                                <label>绒穿<input type="checkbox" data-inspectionItemId="3" class="inspection-item-check" id="inspection-item-3-check" value="on"></label>
                            </legend>
                            <ul id="inspection-item-3-list">
                            </ul>
                        </fieldset>
                        <div class="card-shade">
                            <span class="card-btn"><i class="fa fa-pencil"></i>登记结果</span>
                        </div>
                    </div>
                </li>
                <li class="card-disabled">
                    <div class="card-item">
                        <fieldset>
                            <legend>
                                <label>标本留存<input type="checkbox" data-inspectionItemId="4" class="inspection-item-check" id="inspection-item-4-check" value="on"></label>
                            </legend>
                            <ul id="inspection-item-4-list">
                            </ul>
                        </fieldset>
                        <div class="card-shade">
                            <span class="card-btn"><i class="fa fa-pencil"></i>登记结果</span>
                        </div>
                    </div>
                </li>
            </ol>
        </div>
        <div style="clear: both;">
            <a class="mini-button  mini-btn mini-btn-ok" id="btn-submit">保 存</a>
            <!--<a class="mini-button  mini-btn mini-btn-ok" onclick="CqzdDiagnosisMenuApp.exportThis()">导 出</a>-->
        </div>
    </div>
    <div class="zhezhao" onclick="TipsUtil.toast('先选右边的诊断记录.')"></div>
    <div class="zdmenu">
        <div class="zdmenubuttom">
            <img src="../img/hide.png" >
        </div>
        <div class="rightmenu">
            <div>
                <div class="rightselect">
                    <div class="input-box">
                        <input onkeyup="CqzdDiagnosisMenuApp.search(this.value)" placeholder="搜索诊断记录..."/>
                    </div>
                </div>
                <div class="rightuserconten">
                    <div class="XYuserconten">
                        <div class="righttitle">待处理记录</div>
                        <div class="list-todo">
                        </div>
                    </div>
                    <div class="LSuserconten">
                        <div class="righttitle">历史诊断记录</div>
                        <div class="list-history" hidden>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
<!-- 患者信息模板 -->
<script id="patient-tmpl" type="text/x-jquery-tmpl">
    <span class="username">{%= patientName%}</span><br/>
    <span>就诊号：{%= outpatientNo%}</span><br/>
    <span>身份证号：{%= patientCardId%} <strong style='padding-left:32px;display:inline-block;font-size:16px;color:#555'>{%if fetusesNo-0>1%}多胎{%else%}单胎{%/if%}</strong></span>
</script>
<!-- 羊穿结果模板 -->
<script id="inspection-item-1-tmpl" type="text/x-jquery-tmpl">
    <li><form id="inspection-from-1-{%= index%}">
        <input name="diagnosisId" value="{%= diagnosisId%}" class="mini-hidden">
        <input name="diacrisisId" value="{%= diacrisisId%}" class="mini-hidden">
        <input name="fetusSign" value="{%= fetusSign%}" class="mini-hidden">
        <input name="inspectionItemId" value="1" class="mini-hidden">
        <input name="inspectionItem" value="羊穿" class="mini-hidden">
        <table>
            <caption>F{%= index%}</caption>
            <tr>
                <td>B超标记：</td>
                <td><input name="bSign" class="mini-textbox" value="{%= bSign%}"></td>
            </tr>
            <tr>
                <td>日期：</td>
                <td><input id='inspectionTime-1-{%= index%}' name='inspectionTime' class="mini-datepicker" allowInput="false" value="{%= inspectionTime%}"></td>
            </tr>
            <tr>
                <td>羊水性状：</td>
                <td><input class="mini-combobox txk-dict" id="afTypeId-{%= index%}" name="afTypeId" value="{%= afTypeId%}" showNullItem="true" emptyText=""  dict="CQ_BASE_AF_TYPE" ></td>
            </tr>
            <tr>
                <td>过程：</td>
                <td><input name='inspectionProcess' class="mini-textbox" value="{%= inspectionProcess%}"></td>
            </tr>
            <tr>
                <td colspan="2" style="text-align: left">
                    <dl class="diagnosis-fruit">
                        <dt>结果</dt>
                    </dl>
                </td>
            </tr>
            <tr>
                <td>备注：</td>
                <td><textarea class="mini-textarea" name="inspectionRemark" cols="30" rows="3">{%= inspectionRemark%}</textarea></td>
            </tr>
        </table>
        </form>
    </li>
</script>
<!-- 脐穿结果模板 -->
<script id="inspection-item-2-tmpl" type="text/x-jquery-tmpl">
    <li><form id="inspection-from-2-{%= index%}">
        <input name="diagnosisId" value="{%= diagnosisId%}" class="mini-hidden">
        <input name="diacrisisId" value="{%= diacrisisId%}" class="mini-hidden">
        <input name="fetusSign" value="{%= fetusSign%}" class="mini-hidden">
        <input name="inspectionItemId" value="2" class="mini-hidden">
        <input name="inspectionItem" value="脐穿" class="mini-hidden">
        <table>
            <caption>F{%= index%}</caption>
            <tr>
                <td>B超标记：</td>
                <td><input name="bSign" class="mini-textbox" value="{%= bSign%}"></td>
            </tr>
            <tr>
                <td>日期：</td>
                <td><input id='inspectionTime-2-{%= index%}' name='inspectionTime' class="mini-datepicker" allowInput="false" value="{%= inspectionTime%}"></td>
            </tr>
            <tr>
                <td>穿刺部位：</td>
                <td><input name="puncturePosition" class="mini-textbox" value="{%= puncturePosition%}"></td>
            </tr>
            <tr>
                <td>过程：</td>
                <td><input name='inspectionProcess' class="mini-textbox" value="{%= inspectionProcess%}"></td>
            </tr>
            <tr>
                <td colspan="2" style="text-align: left">
                    <dl class="diagnosis-fruit">
                        <dt>结果</dt>
                    </dl>
                </td>
            </tr>
            <tr>
                <td>备注：</td>
                <td><textarea class="mini-textarea" name="inspectionRemark" cols="30" rows="3">{%= inspectionRemark%}</textarea></td>
            </tr>
        </table>
        </form>
    </li>
</script>
<!-- 绒穿结果模板 -->
<script id="inspection-item-3-tmpl" type="text/x-jquery-tmpl">
    <li><form id="inspection-from-3-{%= index%}">
        <input name="diagnosisId" value="{%= diagnosisId%}" class="mini-hidden">
        <input name="diacrisisId" value="{%= diacrisisId%}" class="mini-hidden">
        <input name="fetusSign" value="" class="mini-hidden">
        <input name="inspectionItemId" value="3" class="mini-hidden">
        <input name="inspectionItem" value="绒穿" class="mini-hidden">
        <table>
            <caption>&nbsp;</caption>
            <tr>
                <td>日期：</td>
                <td><input id='inspectionTime-3-{%= index%}' name='inspectionTime' class="mini-datepicker" allowInput="false" value="{%= inspectionTime%}"></td>
            </tr>
            <tr>
                <td>胎盘部位：</td>
                <td><input name="mazaPosition" class="mini-textbox" value="{%= mazaPosition%}"></td>
            </tr>
            <tr>
                <td>取样量：</td>
                <td><input name="sampleQuantity" class="mini-textbox"  value="{%= sampleQuantity%}"></td>
            </tr>
            <tr>
                <td>过程：</td>
                <td><input name='inspectionProcess' class="mini-textbox" value="{%= inspectionProcess%}"></td>
            </tr>
            <tr>
                <td colspan="2" style="text-align: left">
                    <dl class="diagnosis-fruit">
                        <dt>结果</dt>
                    </dl>
                </td>
            </tr>
            <tr>
                <td>备注：</td>
                <td><textarea class="mini-textarea" name="inspectionRemark" cols="30" rows="3">{%= inspectionRemark%}</textarea></td>
            </tr>
        </table>
        </form>
    </li>
</script>
<!-- 标本留存结果模板 -->
<script id="inspection-item-4-tmpl" type="text/x-jquery-tmpl">
<li><form id="inspection-from-4-{%= index%}">
    <input name="diagnosisId" value="{%= diagnosisId%}" class="mini-hidden">
    <input name="diacrisisId" value="{%= diacrisisId%}" class="mini-hidden">
    <input name="fetusSign" value="" class="mini-hidden">
    <input name="inspectionItemId" value="4" class="mini-hidden">
    <input name="inspectionItem" value="标本留存" class="mini-hidden">
    <table>
        <caption>&nbsp;</caption>
        <tr>
            <td>日期：</td>
            <td><input id='inspectionTime-4-{%= index%}' name='inspectionTime' class="mini-datepicker" allowInput="false" value="{%= inspectionTime%}"></td>
        </tr>
        <tr>
            <td>标本项目：</td>
            <td>
            <input name="specKeepId" class="mini-checkboxlist txk-dict" dict="CQ_BASE_SPEC_KEEP" repeatItems="3" repeatLayout="table" value="{%= specKeepId%}">
        </td>
        </tr>
         <tr>
            <td colspan="2" style="text-align: left">
                <dl class="diagnosis-fruit">
                    <dt>结果</dt>
                </dl>
            </td>
        </tr>
        <tr>
            <td>备注：</td>
            <td><textarea class="mini-textarea" name="inspectionRemark" cols="30" rows="3">{%= inspectionRemark%}</textarea></td>
        </tr>
    </table>
    </form>
</li>
</script>
<!-- 检查结果列表模板 -->
<script id="inspection-result-list-tmpl" type="text/x-jquery-tmpl">
    <dd>
        <label>{%= text%}
        {%if fruitExplain%}
            <input type="checkbox" name="" value="diagnosisFruit[{%= index%}].fruitExplain" checked>
        {%else%}
            <input type="checkbox" name="" value="diagnosisFruit[{%= index%}].fruitExplain">
        {%/if%}
        </label>
        <span class="fruitExplain-input">
            {%if fruitExplain%}
            <input name="diagnosisFruit[{%= index%}].fruitExplain" value="{%= fruitExplain%}" class="mini-textbox">
            {%else%}
            <input name="diagnosisFruit[{%= index%}].fruitExplain" enabled="false" class="mini-textbox">
            {%/if%}
        </span>
        <input name="diagnosisFruit[{%= index%}].fruitTypeName" value="{%= text%}" class="mini-hidden">
        <input name="diagnosisFruit[{%= index%}].fruitTypeId" value="{%= id%}" class="mini-hidden">
    </dd>
</script>
<!-- 右侧菜单里的诊断记录模板 -->
<script id="diacrisis-list-tmpl" type="text/x-jquery-tmpl" data-site="">
    <div class="user" id="user-p{%= diacrisisId%}" onclick="CqzdDiagnosisMenuApp.selectRecord({%= diacrisisId%})">
        <img src="../img/userimg.png">
        <p><span class="thisusername">{%= patientName%}</span>【{%= cardNo%}】<br/>{%= patientCardId%}
        </p>
    </div>
</script>
<script type="text/javascript">
    /**
     * 诊断结果登记的对象
     */
    window.CqzdDiagnosisApp = window.CqzdDiagnosisApp || (function(){

        var resultListEl = '';
        //检查结果类型，来自数据字典【CQ_BASE_FRUIT_TYPE】
        var fruitTypes;
        /**
         * 页面初始化
         */
        var contentInit = function(){
            $("head").append("<link href=\"../css/ZDJGGL.css?v="+ASSETS_VERSION+"\" rel=\"stylesheet\" type=\"text/css\" />");
            //ajax从后台同步加载检查结果类型
            fruitTypes = txkui.getDict('CQ_BASE_FRUIT_TYPE');
            if(fruitTypes){
                for (var i = 0; i < fruitTypes.length; i++) {
                    fruitTypes[i].index = i+1;
                }
                resultListEl = $('#inspection-result-list-tmpl').tmpl(fruitTypes);
            }

            txkui.parse();

            //点击卡片上的“登记”按钮，激活卡片供录入
            $(".card-shade .card-btn").on('click',function () {
                enableCard($(this).closest('.card-item'))
            });
            //点击卡片上的复选框，toggle激活动作
            $(".inspection-item-check").on("change",function () {
                var li = $(this).closest('li');
                if (this.checked){
                    li.removeClass('card-disabled');
                }else{
                    li.addClass('card-disabled');
                };
            });

            //点击卡片上的检查结果复选框，toggle该检查结果项目
            $("body").on('click', ".diagnosis-fruit [type=checkbox]", function(){
                var checked = this.checked;
                var inputMini = mini.getbyName(this.value,$(this).parent().parent()[0]);
                if(checked){
                    inputMini.setEnabled(true);
                }else{
                    //清空输入的内容
                    inputMini.setValue('');
                    inputMini.setEnabled(false);
                }
            });

            //保存提交按钮
            var btn = $("#btn-submit");
            btn.on("click",function(){
                /*
                * 处理思路
                * 1.将页面中的所有卡片中form中的值取出来
                * 2.卡片中过滤未勾选的检测结果
                * 3.过滤掉没有被选中【激活】的card的内容
                * 4.确认提交结果
                * dataArr为空则调用删除接口，dataArr不为空则调用保存接口
                * */
                var forms = $("form");
                var dataArr = [];
                var diacrisisId;
                //将页面中的所有卡片中form中的值取出来
                for (var i = 0; i < forms.length; i++) {
                    var form = new mini.Form('#'+forms[i].id);
                    if (!form.validate()){
                        return;
                    }
                    var data = form.getData(true, true);
                    if (data.inspectionItemId-0 === 4){
                        data.specKeepName = mini.getbyName('specKeepId').getSelecteds().map(item => {return item.text}).join(',');
                    }
                    diacrisisId = data.diacrisisId;
                    //过滤未勾选的检测结果
                    var diagnosisFruit = data.diagnosisFruit;
                    for (var j = 0; j < diagnosisFruit.length; j++) {
                        if(!diagnosisFruit[j].fruitTypeId){
                            diagnosisFruit.splice(j--,1);
                        }
                    }
                    dataArr.push(data);
                }
                //过滤掉没有选中的card内容
                var itemList = $(".inspection-item-check"),item;
                for (var i = 0; i < itemList.length; i++) {
                    var inspectionItemId =itemList[i].dataset.inspectionitemid-0;
                    if(!itemList[i].checked){
                        for (var j = 0; j < dataArr.length; j++) {
                            if(dataArr[j].inspectionItemId-0 === inspectionItemId){
                                dataArr.splice(j--,1);
                            }
                        }
                    }else{
                        item = dataArr.search(inspectionItemId,['inspectionItemId'])[0];
                        if(!item.inspectionTime){
                             TipsUtil.toastErr(item.fetusSign+item.inspectionItem+"的检查日期不能为空");
                            return;
                        }
                        if(item.inspectionItemId == 1 || item.inspectionItemId == 2){
                            //羊穿 || 脐穿
                            if(!item.bSign){
                                 TipsUtil.toastErr(item.fetusSign+item.inspectionItem+"的B超标记不能为空");
                                return;
                            }
                        }
                        if(item.inspectionItemId == 1 || item.inspectionItemId == 2 || item.inspectionItemId == 3){
                            if(!item.inspectionProcess){
                                 TipsUtil.toastErr(item.fetusSign+item.inspectionItem+"检查过程不能为空");
                                return;
                            }
                        }
                        if(item.inspectionItemId == 1){
                            //羊穿
                            if(!item.afTypeId){
                                 TipsUtil.toastErr(item.fetusSign+item.inspectionItem+"的羊水性状不能为空");
                                return;
                            }
                        }
                        if(item.inspectionItemId == 2){
                            //脐穿
                            if(!item.puncturePosition){
                                 TipsUtil.toastErr(item.fetusSign+item.inspectionItem+"的穿刺部位不能为空");
                                return;
                            }
                        }
                        if(item.inspectionItemId == 3){
                            //绒穿
                            if(!item.mazaPosition){
                                 TipsUtil.toastErr(item.inspectionItem+"的胎盘部位不能为空");
                                return;
                            }
                            if(!item.sampleQuantity){
                                 TipsUtil.toastErr(item.inspectionItem+"的取样量不能为空");
                                return;
                            }
                        }
                        if(item.inspectionItemId == 4){
                            //标本留存
                            if(!item.specKeepId){
                                 TipsUtil.toastErr("标本留存项目不能为空");
                                return;
                            }
                        }

                    }
                }
                //dataArr为空则调用删除接口，dataArr不为空则调用保存接口
                if (dataArr.length){
                    mini.confirm("确定保存诊断结果吗？","",function(action){
                        if("ok" !== action){
                            return;
                        }
                        btn.attr("disabled","disabled");
                        HttpUtil.post(SVR_PATH+"cqzd/do/diagnosis/save",JSON.stringify(dataArr),function(e){
                            btn.removeAttr("disabled");
                            if(e.msg){
                                return mini.alert(e.msg);
                            }
                            TipsUtil.toast('保存成功');
                            CqzdDiagnosisMenuApp.reload();
                        },function () {
                            btn.removeAttr("disabled");
                        });
                    });
                }else {
                    mini.confirm("确定删除诊断结果吗？","",function(action){
                        if("ok" !== action){
                            return;
                        }
                        btn.attr("disabled","disabled");
                        HttpUtil.delete(SVR_PATH+"cqzd/do/diagnosis/delete/"+diacrisisId,null,function(e){
                            btn.removeAttr("disabled");
                            if(e.msg){
                                return mini.alert(e.msg);
                            }
                            TipsUtil.toast('删除成功');
                            CqzdDiagnosisMenuApp.reload();

                        },function () {
                            btn.removeAttr("disabled");
                        });
                    });
                }

            });
        };

        /**
         * 激活卡片
         * 选中inspection-item-check复选框
         * @param card
         */
        var enableCard = function(card){
            var checkEl = card.find('.inspection-item-check');
            checkEl[0].checked = true;
            checkEl.trigger('change');
        };



        /**
         * 从后台查询诊断记录，判断该记录是否有诊断结果
         * 先按照诊断记录中的胎儿数量，初始化诊断结果登记卡片
         * 然后如果有诊断结果，则根据已有的诊断结果把数据填充到卡片上
         * @param diacrisisId 诊断记录ID
         */
        var selectDiacrisis = function (diacrisisId) {

            var tmplResult = $("#inspection-result-list-tmpl");
            //诊断结果对象，其中iten-1等表示每个检查类型的结果项集合
            var inspectionItem = {};
            //羊穿【0~N次】
            inspectionItem['item-1'] = [];
            //脐穿【0~N次】
            inspectionItem['item-2'] = [];
            //绒穿【0~1次】
            inspectionItem['item-3'] = [];
            //标本留存【0~1次】
            inspectionItem['item-4'] = [];

            //准备结果
            for (var j = 0; j < fruitTypes.length; j++) {
                delete fruitTypes[j].fruitExplain;
            }
            //清除card的激活状态
            $(".inspection-item-check").each(function () {
                this.checked = false;
                $(this).trigger('change');
            });

            HttpUtil.get(SVR_PATH+"cqzd/do/diagnosis/getByDiacrisis/"+diacrisisId,function (e) {

                patientCardId=e.diacrisisInfo.patientCardId;
                var data = e.data,itemId,item,i,j;
                //诊断记录
                var diacrisisInfo = e.diacrisisInfo;
                var lisData = e.lis;
                //附件lis接口中的结果到回显数据中
                //appendLisResult2(e);

                //将患者信息渲染到页面
                $("#patient-tmpl").tmpl(diacrisisInfo).appendTo($('.usertext').html(''));
                //诊断记录上的胎儿数量
                var fetusesNo = diacrisisInfo.fetusesNo-0;
                //根据该数量初始化诊断结果登记卡片
                for (i = 0; i < fetusesNo; i++) {
                    //羊穿和脐穿的卡片数量等于胎儿的数量、
                    //羊穿
                    inspectionItem['item-1'].push({
                        index:(i+1)
                        ,diacrisisId:diacrisisId
                        ,fetusSign:'F'+(i+1)
                        ,resultListEl: tmplResult.tmpl(fruitTypes)
                    });
                    //脐穿
                    inspectionItem['item-2'].push({
                        index:(i+1)
                        ,diacrisisId:diacrisisId
                        ,fetusSign:'F'+(i+1)
                        ,resultListEl: tmplResult.tmpl(fruitTypes)
                    });
                }
                //即使多胎，最多也只做一次绒穿，一次标本留存
                //绒穿
                inspectionItem['item-3'].push({
                    diacrisisId:diacrisisId
                    ,resultListEl: tmplResult.tmpl(fruitTypes)
                });
                //标本留存
                inspectionItem['item-4'].push({
                    diacrisisId:diacrisisId
                    ,resultListEl: tmplResult.tmpl(fruitTypes)
                });

                if(data && data.length){
                    //这是已登记过检验结果的诊断记录,做修改更新操作
                    for (i = 0; i < data.length; i++) {
                        //将结果数据填充到卡片上
                        for (j = 0; j < fruitTypes.length; j++) {
                            for (var k = 0; k < data[i].diagnosisFruit.length; k++) {
                                //根据检查结果名称来匹配卡片检查结果
                                if(fruitTypes[j].text === data[i].diagnosisFruit[k].fruitTypeName){
                                    fruitTypes[j].fruitExplain = data[i].diagnosisFruit[k].fruitExplain;
                                }
                            }
                        }
                        //输入检查结果的html
                        data[i].resultListEl =  tmplResult.tmpl(fruitTypes);

                        itemId = data[i].inspectionItemId;
                        item = inspectionItem['item-'+itemId];
                        if(item){
                            //根据诊断结果中的胎儿标记来确定每条结果对应的卡片，同时激活目标卡片
                            for (var j = 0; j < item.length; j++) {
                                if (itemId === 3 || itemId === 4 || item[j].fetusSign === data[i].fetusSign){
                                    data[i].index = item[j].index;
                                    item[j] = data[i];
                                    enableCard($('#inspection-item-'+itemId+'-check').closest('.card-item'));
                                    break;
                                }
                            }
                        }
                    }
                }
                //遍历诊断结果对象，将其中的结果项目加上【检查结果输入的HTML(resultListEl)】
                var tmpl,tmplEl,box;
                for (var m in inspectionItem) {
                    if (!inspectionItem.hasOwnProperty(m)){continue}
                    tmpl = $("#inspection-"+m+"-tmpl");
                    box = $("#inspection-"+m+"-list");
                    box.html('');
                    for (i = 0; i < inspectionItem[m].length; i++) {
                        tmplEl = tmpl.tmpl(inspectionItem[m][i]);
                        tmplEl.find('.diagnosis-fruit').append(inspectionItem[m][i].resultListEl);
                        tmplEl.appendTo(box);
                    }
                }
                setTimeout(function(){
                    txkui.parse();
                    setTimeout(function () {
                        appendLisResult(lisData,fetusesNo);
                        /*$('.card-item').each(function () {
                            $(this).find('[type=text][name^=diagnosisFruit]').each(function(index,item){
                                if(item.value){
                                    mini.getbyName(item.name).setValue(item.value);
                                }
                            })
                        })*/

                    },500)
                },200);
            });
        };



        var INSPECTION_ITEM_LIST = [{fetusSign:'F1',inspectionItemId:1,inspectionItem:'羊穿',lisCode:'羊水'},
            {inspectionItemId:3,inspectionItem:'绒穿',lisCode:'绒毛'},
            {inspectionItemId:4,inspectionItem:'样本留存',lisCode:'流产物'},
            {fetusSign:'F1',inspectionItemId:2,inspectionItem:'脐穿',lisCode:'脐血'}];

        var FRUIT_LIST = [{fruitTypeId:1,fruitTypeName:'核型分析',lisCode:'染色体分析'},
            {fruitTypeId:2,fruitTypeName:'FISH',lisCode:'细胞荧光原位杂交检测'},
            {fruitTypeId:3,fruitTypeName:'CNV',lisCode:'CNV'},
            {fruitTypeId:4,fruitTypeName:'QF-PCR',lisCode:'QF-PCR'},
            {fruitTypeId:5,fruitTypeName:'其他',lisCode:'其他'}];

        /**
         * 将LIS接口结果赋值到页面中
         * */
        function appendLisResult(lisData,fetusesNo) {
            if(!lisData || !lisData.length){
                return;
            }
            $.each(lisData,function (idx1,item) {

                var inspectionItemId = null;
                $.each(INSPECTION_ITEM_LIST,function (idx2,ins) {
                    if(item.types[0].indexOf(ins.lisCode) !== -1){
                        inspectionItemId = ins.inspectionItemId;
                    }
                });
                var fruitTypeId=null;
                $.each(FRUIT_LIST,function (idx3,fruit) {
                    if(item.categoryCode.indexOf(fruit.lisCode) !== -1){
                        fruitTypeId = fruit.fruitTypeId;
                    }
                });
                if(!inspectionItemId){
                    return;
                }
                for (var i = 0; i < fetusesNo; i++) {
                    var formId = '#inspection-from-'+inspectionItemId+"-";
                    var inspectionTimeId = "inspectionTime-"+inspectionItemId+"-";
                    if(inspectionItemId<3){
                        formId += (i+1);
                        inspectionTimeId += (i+1);
                    }

                    //日期赋值到卡片中
                    var insDateEl = mini.get(inspectionTimeId);
                    if(!insDateEl.getValue()){
                        insDateEl.setValue(item.effectiveDateTime);
                    }
                    //激活卡片
                    enableCard($(insDateEl.el).closest('.card-item'))
                    if(!fruitTypeId){
                        return;
                    }
                    var fruitEl = $(formId+" [name='diagnosisFruit["+fruitTypeId+"].fruitExplain']");
                    if(!fruitEl.val()){
                        //结果赋值
                        var chkBox = fruitEl.closest('dd').find('[type=checkbox]');
                        chkBox.attr("checked","checked");
                        var inputMini = mini.getbyName(chkBox[0].value,chkBox.parent().parent()[0]);
                        fruitEl.val(item.result);
                        inputMini.setEnabled(true);
                    }
                }



            });

        }

        return {
            init:function(){
                contentInit();
            }
            ,selectDiacrisis:selectDiacrisis
        }
    })();

    $(function() {

        CqzdDiagnosisApp.init()
        if (window.top === window.self) { // are you trying to put self in an iframe?
            var getParameters = function (url) {
                var nameValues = [];
                if (url) {
                    if (url.indexOf('?') == -1) {
                        return nameValues.push({ baseUrl: url });
                    };
                    var arrUrlParts = url.split('?');
                    var baseUrl = arrUrlParts[0];
                    var urlParameters=arrUrlParts[1].split('&');
                    for (var i = 0; i < urlParameters.length; i++) {
                        var nameValue = urlParameters[i].split('=');
                        nameValues.push({ baseUrl: baseUrl, key: nameValue[0], urlvalue: nameValue[1]});
                    };
                    return nameValues;
                };
            };
             parameter = getParameters(window.location.href)[0];
            if (parameter){
                var sysid=parameter.urlvalue;
                CqzdDiagnosisMenuApp.selectRecord(sysid)
            }

        }
    })

    /**
     * 诊断记录列表
     * 右侧菜单
     */
    window.CqzdDiagnosisMenuApp = window.CqzdDiagnosisMenuApp || (function () {

        var searchKey;
        var selectedItem;
        /**
         * 菜单初始化
         */
        var contentInit = function () {
            //菜单展开/收缩
            var menuEl = $('.rightmenu');
            $('.zdmenubuttom').click(function() {
                menuEl.animate({width: 'toggle'}, 350);
                menuEl.parent().toggleClass("hidden");
            });
            //点击其他地方隐藏右侧
            $(".bigdiv").click(function(){
                if (menuEl.is(":visible")) {
                    menuEl.animate({width: 'toggle'}, 350);
                    menuEl.parent().toggleClass("hidden");
                }
            })

            //菜单中的栏目展开/收缩
            $('.righttitle').click(function() {
                $(this).next().animate({
                    height: 'toggle'
                }, 350);
            });
        };

        /**
         * 搜索诊断记录
         */
        var search = function (keyword) {
            searchKey = keyword;
            reload();
        };
        /**
         * 重新从后台加载诊断记录
         * @param callback
         */
        var reload = function(callback){
            //右侧菜单项模板
            var tmplEl = $("#diacrisis-list-tmpl");
            $.post(SVR_PATH+"cqzd/do/diagnosis/listDiacrisis", {'key': searchKey||null},function (e) {
                if(HttpUtil.hasErr(e)){
                    return;
                }
                $('.list-todo').html('').append(tmplEl.tmpl(e.todoList));
                $('.list-history').html('').append(tmplEl.tmpl(e.histories));
                if(callback){
                    callback(e);
                }
                if(selectedItem){
                    $("#user-p"+selectedItem).addClass('selected');
                }
            });
        };
        /**
         * 选中诊断记录
         * @param diacrisisId 诊断记录ID
         */
        var selectRecord = function (diacrisisId) {
            selectedItem = diacrisisId;
            $(".user").removeClass('selected');
            $("#user-p"+selectedItem).addClass('selected');
            $(".zhezhao").fadeOut(300);
            CqzdDiagnosisApp.selectDiacrisis(diacrisisId);
        };
        //导出
        var exportThis=function () {
            window.open('/cqzd/Laboratory/selLaboratoryAll?patientCardId='+patientCardId)
        }
        return {
            init:function () {
                contentInit();
                search();
            }
            ,search:search
            ,reload:reload
            ,selectRecord:selectRecord
            ,exportThis:exportThis
        }
    })();
    //身份证
    var patientCardId;
    $(function() {CqzdDiagnosisMenuApp.init()})
</script>
</body>
</html>
